package com.zb.controller;

import com.zb.pojo.Book;
import com.zb.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author zhs
 * @create 2020-07-22-12:42
 */
@Controller
@RequestMapping(value = "/thymeleaf")
public class ThymeleafController {

    @Autowired
    private BookService bookService;

    @RequestMapping(value = "/test")
    public String test(Model model, HttpSession session){
        System.out.println("thymeleaf你大爷");
        model.addAttribute("username1","张三");
        model.addAttribute("age",12);
        session.setAttribute("username2","李四");
        List<Book> bookList = bookService.findAll();
        model.addAttribute("bookList",bookList);
        return "index";
    }

}
